package rad.framework.uml2.uml.edit.providers.elementItemProvider.linkEnd;

import java.util.Collection;
import java.util.List;

import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertySource;
import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.ViewerNotification;
import org.eclipse.uml2.uml.LinkEndDestructionData;
import org.eclipse.uml2.uml.UMLPackage;

import rad.framework.uml2.uml.edit.UMLEditPlugin;

public class LinkEndDestructionDataItemProvider
		extends LinkEndDataItemProvider
		implements IEditingDomainItemProvider, IStructuredItemContentProvider, ITreeItemContentProvider, IItemLabelProvider, IItemPropertySource {

	public LinkEndDestructionDataItemProvider(AdapterFactory adapterFactory) {
		super(adapterFactory);
	}

	@Override
	public List getPropertyDescriptors(Object object) {
		if (itemPropertyDescriptors == null) {
			super.getPropertyDescriptors(object);

			addIsDestroyDuplicatesPropertyDescriptor(object);
			addDestroyAtPropertyDescriptor(object);
		}
		return itemPropertyDescriptors;
	}

	protected void addIsDestroyDuplicatesPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_LinkEndDestructionData_isDestroyDuplicates_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_LinkEndDestructionData_isDestroyDuplicates_feature", "_UI_LinkEndDestructionData_type"),
				UMLPackage.Literals.LINK_END_DESTRUCTION_DATA__IS_DESTROY_DUPLICATES, true, ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE, null, null));
	}

	protected void addDestroyAtPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_LinkEndDestructionData_destroyAt_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_LinkEndDestructionData_destroyAt_feature", "_UI_LinkEndDestructionData_type"),
				UMLPackage.Literals.LINK_END_DESTRUCTION_DATA__DESTROY_AT, true, null, null, null));
	}

	@Override
	public Object getImage(Object object) {
		return overlayImage(object, getResourceLocator().getImage("full/obj16/LinkEndDestructionData"));
	}

	@Override
	public String getText(Object object) {
		final LinkEndDestructionData linkEndDestructionData = (LinkEndDestructionData) object;
		return getString("_UI_LinkEndDestructionData_type") + " " + linkEndDestructionData.isDestroyDuplicates();
	}

	@Override
	public void notifyChanged(Notification notification) {
		updateChildren(notification);

		switch (notification.getFeatureID(LinkEndDestructionData.class)) {
			case UMLPackage.LINK_END_DESTRUCTION_DATA__IS_DESTROY_DUPLICATES:
				fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
				return;
		}
		super.notifyChanged(notification);
	}

	@Override
	protected void collectNewChildDescriptors(Collection newChildDescriptors, Object object) {
		super.collectNewChildDescriptors(newChildDescriptors, object);
	}

	@Override
	public ResourceLocator getResourceLocator() {
		return UMLEditPlugin.INSTANCE;
	}

}
